#ifndef COMMINUCATIONTHREAD_H
#define COMMINUCATIONTHREAD_H

#include <QThread>
#include <QUdpSocket>
#include <QMutex>



#define SPEECHSERVER_PORT    9876
#define REMOTECONTROLL_PORT (SPEECHSERVER_PORT+1)
#define LOG_PORT            (SPEECHSERVER_PORT+2)

class ComminucationHandler : public QThread
{
    Q_OBJECT
private:
    QMutex *mutex;
    QUdpSocket *socket;
    bool working;
    int port;
    QHostAddress address;
    QMap<QString,int> ports;
    void run();
    void assignPorts();
public:
    explicit ComminucationHandler(int _port, QHostAddress _address, QObject *parent=0);
    ~ComminucationHandler()
    {
        working=false;
        quit();
        wait();
        socket->close();
        delete mutex;
        delete socket;
    }
    void stop();
    void sendCommand(QString target, QString command);
Q_SIGNALS:
    void MessageRecieved(QString target,QString result);
public Q_SLOTS:
    
};

#endif // COMMINUCATIONTHREAD_H
